home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 140
/
(Vol 140) Sep 19 2011.iso
/
Games
/
world-wars.swf
/
scripts
/
__Packages
/
classes
/
Map.as
< prev
Wrap
Text File
|
2011-09-19
|
29KB
|
850 lines
class classes.Map
{
var TERRITORY_SIZE_min = 17;
var TERRITORY_SIZE_max = 28;
var BORDER_COLOR = 4143636;
var BORDER_ACTIVE_COLOR = 16777215;
var BORDER_OVER_COLOR = 13421772;
var BORDER_SIZE = 2;
var AV_UNITS_PER_TERRITORY = 3;
var COLOR_ARR = [11304249,7041575,4541257,10439479,5801101,7419137,8092812,4866561];
function Map(rmc, gc)
{
this.ROOT_MC = rmc;
this.GAME_CLASS = gc;
this.HEX = new classes.models.Hex();
this.cos30 = Math.cos(this.deg2rad(30));
this.cos60 = Math.cos(this.deg2rad(60));
this.sin60 = Math.sin(this.deg2rad(60));
}
function createMap(players)
{
var _loc23_ = 34;
var _loc24_ = 29;
var _loc27_ = 30;
var _loc28_ = 34;
var _loc26_ = this.random2(_loc28_ - _loc27_) + _loc27_;
if(this.rubbish_arr.length > 0)
{
this.clearAll();
}
this.rubbish_arr = new Array();
this.CHOSEN_TERR_A = this.CHOSEN_TERR_B = undefined;
this.TERRITORIES_ARR = new Array();
this.MAP_ARR = new Array();
this.counter = 0;
this.drawGrid(_loc23_,_loc24_);
while(this.TERRITORIES_ARR.length < _loc26_)
{
var _loc10_ = undefined;
var _loc9_ = undefined;
if(this.TERRITORIES_ARR.length == 0)
{
var _loc13_ = Math.round((_loc23_ - 1) / 2);
var _loc12_ = Math.round((_loc24_ - 1) / 2);
_loc10_ = Math.round(0.25 * _loc13_ + this.random2(0.5 * _loc13_));
_loc9_ = Math.round(0.25 * _loc12_ + this.random2(0.5 * _loc12_));
}
else
{
var _loc8_ = false;
while(!_loc8_)
{
var _loc5_ = this.random2(this.TERRITORIES_ARR.length - 1);
var _loc6_ = this.TERRITORIES_ARR[_loc5_].arr.length - 1;
while(_loc6_ >= 0)
{
var _loc3_ = this.freeNeighboursArr2(this.TERRITORIES_ARR[_loc5_].arr[_loc6_]);
if(_loc3_.length > 0)
{
var _loc4_ = this.random2(_loc3_.length - 1);
_loc10_ = _loc3_[_loc4_].x;
_loc9_ = _loc3_[_loc4_].y;
_loc8_ = true;
}
_loc6_ = _loc6_ - 1;
}
}
}
var _loc7_ = this.newTerritory(_loc10_,_loc9_);
if(_loc7_.length > 0)
{
var _loc11_ = {status:0,player:0,border:undefined,army:0,unitsMC:undefined,unitsNO:0,arr:_loc7_};
_loc6_ = 0;
while(_loc6_ < _loc7_.length)
{
_loc7_[_loc6_]._territory = _loc11_;
_loc6_ = _loc6_ + 1;
}
this.TERRITORIES_ARR.push(_loc11_);
}
}
var _loc25_ = _root.ARMY;
var _loc15_ = new Array();
_loc6_ = 0;
while(_loc6_ < players)
{
_loc15_.push((_loc6_ + _loc25_ - 1) % 3 + 1);
_loc6_ = _loc6_ + 1;
}
_loc6_ = 0;
while(_loc6_ < this.TERRITORIES_ARR.length)
{
this.makeBorder(this.TERRITORIES_ARR[_loc6_],this.HEX.__get__HEIGHT() / 2);
this.markTerritory(this.TERRITORIES_ARR[_loc6_],players - _loc6_ % players,0);
this.TERRITORIES_ARR[_loc6_].army = _loc15_[this.TERRITORIES_ARR[_loc6_].player - 1];
_loc6_ = _loc6_ + 1;
}
this.randomUnits(players);
}
function startInterface()
{
this.selectA();
}
function markTerritory(terrObj, pl, stat)
{
var _loc2_ = 0;
while(_loc2_ < terrObj.arr.length)
{
terrObj.arr[_loc2_]._visible = true;
terrObj.arr[_loc2_].gotoAndStop(pl);
_loc2_ = _loc2_ + 1;
}
this.colorMC(terrObj.border,this.BORDER_COLOR);
terrObj.status = stat;
terrObj.player = pl;
}
function drawGrid(w, h)
{
var _loc11_ = this.HEX.__get__WIDTH();
var _loc7_ = 0;
while(_loc7_ < h)
{
var _loc8_ = new Array();
var _loc6_ = 0;
while(_loc6_ < w)
{
var _loc5_ = this.ROOT_MC.attachMovie("HEX","hex_" + _loc6_ + "x" + _loc7_,this.counter++);
_loc5_._x = _loc6_ * this.HEX.__get__WIDTH() + _loc7_ % 2 * (this.HEX.__get__WIDTH() / 2);
_loc5_._y = _loc7_ * (this.HEX.__get__HEIGHT() / 2) * 1.5;
_loc8_.push(_loc5_);
_loc5_.x = _loc6_;
_loc5_.y = _loc7_;
_loc5_._inTerritory = false;
_loc5_._onBorder = false;
_loc5_._visible = false;
this.rubbish_arr.push(_loc5_);
_loc6_ = _loc6_ + 1;
}
this.MAP_ARR.push(_loc8_);
_loc7_ = _loc7_ + 1;
}
var _loc3_ = 0;
while(_loc3_ < h)
{
var _loc2_ = 0;
while(_loc2_ < w)
{
var _loc4_ = this.MAP_ARR[_loc3_][_loc2_];
_loc4_.L = this.MAP_ARR[_loc3_][_loc2_ - 1];
_loc4_.R = this.MAP_ARR[_loc3_][_loc2_ + 1];
if(_loc3_ % 2 == 0)
{
_loc4_.TL = this.MAP_ARR[_loc3_ - 1][_loc2_ - 1];
_loc4_.TR = this.MAP_ARR[_loc3_ - 1][_loc2_];
_loc4_.BL = this.MAP_ARR[_loc3_ + 1][_loc2_ - 1];
_loc4_.BR = this.MAP_ARR[_loc3_ + 1][_loc2_];
}
else
{
_loc4_.TL = this.MAP_ARR[_loc3_ - 1][_loc2_];
_loc4_.TR = this.MAP_ARR[_loc3_ - 1][_loc2_ + 1];
_loc4_.BL = this.MAP_ARR[_loc3_ + 1][_loc2_];
_loc4_.BR = this.MAP_ARR[_loc3_ + 1][_loc2_ + 1];
}
_loc2_ = _loc2_ + 1;
}
_loc3_ = _loc3_ + 1;
}
}
function newTerritory(x, y)
{
var _loc2_ = new Array(this.MAP_ARR[y][x]);
this.MAP_ARR[y][x]._inTerritory = true;
var _loc8_ = this.random2(Math.round(this.TERRITORY_SIZE_max - this.TERRITORY_SIZE_min)) + this.TERRITORY_SIZE_min;
var _loc7_ = false;
while(_loc2_.length < _loc8_ && !_loc7_)
{
var _loc6_ = 0;
_loc2_ = this.shuffledArray(_loc2_);
var _loc3_ = 0;
while(_loc3_ < _loc2_.length)
{
var _loc4_ = this.freeNeighboursArr2(_loc2_[_loc3_]);
if(_loc4_.length > 0)
{
var _loc5_ = _loc4_[this.random2(_loc4_.length - 1)];
_loc2_.push(_loc5_);
_loc5_._inTerritory = true;
_loc3_ = _loc2_.length + 10;
}
else
{
_loc6_ = _loc6_ + 1;
}
_loc3_ = _loc3_ + 1;
}
if(_loc6_ >= _loc2_.length)
{
_loc7_ = true;
}
}
if(_loc7_)
{
if(_loc2_.length >= this.TERRITORY_SIZE_min)
{
return _loc2_;
}
this.burnTerritory(_loc2_);
return new Array();
}
return _loc2_;
}
function neighbourTerritoriesNo(terrArr)
{
var _loc6_ = new Array();
var _loc7_ = 0;
while(_loc7_ < terrArr.length)
{
var _loc5_ = terrArr[_loc7_];
var _loc3_ = [_loc5_.TL,_loc5_.L,_loc5_.TR,_loc5_.BR,_loc5_.R,_loc5_.BL];
var _loc1_ = 0;
while(_loc1_ < _loc3_.length)
{
if(_loc3_[_loc1_]._territory != _loc5_._territory && _loc3_[_loc1_]._territory != undefined)
{
var _loc4_ = false;
var _loc2_ = 0;
while(_loc2_ < _loc6_.length && !_loc4_)
{
if(_loc6_[_loc2_] == _loc3_[_loc1_]._territory)
{
_loc4_ = true;
}
_loc2_ = _loc2_ + 1;
}
if(!_loc4_)
{
_loc6_.push(_loc3_[_loc1_]._territory);
}
}
_loc1_ = _loc1_ + 1;
}
_loc7_ = _loc7_ + 1;
}
return _loc6_.length;
}
function freeNeighboursArr(mc)
{
var _loc3_ = new Array();
var _loc2_ = [mc.TL,mc.L,mc.TR,mc.BR,mc.R,mc.BL];
var _loc1_ = 0;
while(_loc1_ < _loc2_.length)
{
if(_loc2_[_loc1_] != undefined && _loc2_[_loc1_]._inTerritory == false)
{
_loc3_.push(_loc2_[_loc1_]);
}
_loc1_ = _loc1_ + 1;
}
return _loc3_;
}
function freeNeighboursArr2(mc)
{
var _loc4_ = new Array();
var _loc2_ = [mc.TL,mc.L,mc.TR,mc.BR,mc.R,mc.BL,mc.L,mc.R,mc.L,mc.R];
var _loc1_ = 0;
while(_loc1_ < _loc2_.length)
{
if(_loc2_[_loc1_] != undefined && _loc2_[_loc1_]._inTerritory == false)
{
_loc4_.push(_loc2_[_loc1_]);
}
_loc1_ = _loc1_ + 1;
}
return _loc4_;
}
function burnTerritory(terrArr)
{
var _loc1_ = 0;
while(_loc1_ < terrArr.length)
{
terrArr[_loc1_]._inTerritory = true;
_loc1_ = _loc1_ + 1;
}
}
function makeBorder(terrObj, r)
{
var _loc7_ = this.BORDER_SIZE;
var _loc6_ = this.BORDER_COLOR;
var _loc11_ = new Array();
var _loc10_ = 0;
while(_loc10_ < terrObj.arr.length)
{
var _loc8_ = terrObj.arr[_loc10_];
var _loc9_ = [_loc8_.TL,_loc8_.L,_loc8_.TR,_loc8_.BR,_loc8_.R,_loc8_.BL];
var _loc5_ = 0;
while(_loc5_ < _loc9_.length)
{
if(_loc9_[_loc5_]._territory != terrObj && !_loc8_._onBorder)
{
_loc8_._onBorder = true;
_loc11_.push(_loc8_);
}
_loc5_ = _loc5_ + 1;
}
_loc10_ = _loc10_ + 1;
}
var _loc2_ = this.ROOT_MC.createEmptyMovieClip("border" + this.counter,this.counter++);
_loc2_._x = _loc11_[0]._x;
_loc2_._y = _loc11_[0]._y;
terrObj.border = _loc2_;
this.rubbish_arr.push(_loc2_);
_loc10_ = 0;
while(_loc10_ < _loc11_.length)
{
_loc8_ = _loc11_[_loc10_];
var _loc4_ = _loc8_._x - _loc2_._x;
var _loc3_ = _loc8_._y - _loc2_._y;
_loc9_ = [_loc8_.TL,_loc8_.L,_loc8_.TR,_loc8_.BR,_loc8_.R,_loc8_.BL];
_loc5_ = 0;
while(_loc5_ < _loc9_.length)
{
if(_loc9_[_loc5_]._territory != _loc8_._territory || _loc9_[_loc5_] == undefined)
{
switch(_loc5_)
{
case 5:
_loc2_.lineStyle(_loc7_,_loc6_,100);
_loc2_.moveTo(_loc4_ + this.HEX.__get__BL().x,_loc3_ + this.HEX.__get__BL().y);
_loc2_.lineTo(_loc4_ + this.HEX.__get__B().x,_loc3_ + this.HEX.__get__B().y);
break;
case 1:
_loc2_.lineStyle(_loc7_,_loc6_,100);
_loc2_.moveTo(_loc4_ + this.HEX.__get__BL().x,_loc3_ + this.HEX.__get__BL().y);
_loc2_.lineTo(_loc4_ + this.HEX.__get__TL().x,_loc3_ + this.HEX.__get__TL().y);
break;
case 3:
_loc2_.lineStyle(_loc7_,_loc6_,100);
_loc2_.moveTo(_loc4_ + this.HEX.__get__BR().x,_loc3_ + this.HEX.__get__BR().y);
_loc2_.lineTo(_loc4_ + this.HEX.__get__B().x,_loc3_ + this.HEX.__get__B().y);
break;
case 2:
_loc2_.lineStyle(_loc7_,_loc6_,100);
_loc2_.moveTo(_loc4_ + this.HEX.__get__TR().x,_loc3_ + this.HEX.__get__TR().y);
_loc2_.lineTo(_loc4_ + this.HEX.__get__T().x,_loc3_ + this.HEX.__get__T().y);
break;
case 4:
_loc2_.lineStyle(_loc7_,_loc6_,100);
_loc2_.moveTo(_loc4_ + this.HEX.__get__TR().x,_loc3_ + this.HEX.__get__TR().y);
_loc2_.lineTo(_loc4_ + this.HEX.__get__BR().x,_loc3_ + this.HEX.__get__BR().y);
break;
case 0:
_loc2_.lineStyle(_loc7_,_loc6_,100);
_loc2_.moveTo(_loc4_ + this.HEX.__get__TL().x,_loc3_ + this.HEX.__get__TL().y);
_loc2_.lineTo(_loc4_ + this.HEX.__get__T().x,_loc3_ + this.HEX.__get__T().y);
}
}
_loc5_ = _loc5_ + 1;
}
_loc10_ = _loc10_ + 1;
}
}
function randomUnits(players)
{
var _loc12_ = Math.round(this.AV_UNITS_PER_TERRITORY * this.TERRITORIES_ARR.length);
var _loc9_ = new Array();
var _loc10_ = new Array();
var _loc5_ = 0;
while(_loc5_ < players)
{
_loc9_.push(Math.floor(_loc12_ / players));
_loc5_ = _loc5_ + 1;
}
_loc5_ = 0;
while(_loc5_ < _loc12_ - Math.floor(_loc12_ / players) * players)
{
_loc9_[_loc9_.length - 1 - _loc5_] += 1;
_loc5_ = _loc5_ + 1;
}
var _loc15_ = Math.floor(this.TERRITORIES_ARR.length / players);
var _loc14_ = this.TERRITORIES_ARR.length - players * Math.floor(this.TERRITORIES_ARR.length / players);
_loc5_ = 0;
while(_loc5_ < players)
{
_loc10_.push(_loc15_);
_loc5_ = _loc5_ + 1;
}
_loc5_ = 0;
while(_loc5_ < _loc14_)
{
_loc10_[_loc10_.length - 1 - _loc5_] += 1;
_loc5_ = _loc5_ + 1;
}
var _loc13_ = new Array();
var _loc11_ = new Array();
_loc5_ = 0;
while(_loc5_ < players)
{
var _loc4_ = _loc9_[_loc5_];
var _loc7_ = _loc10_[_loc5_];
var _loc8_ = new Array();
var _loc3_ = 0;
while(_loc3_ < _loc7_)
{
var _loc2_ = 0;
while(_loc2_ > 8 || _loc2_ < 1)
{
_loc2_ = this.random2(Math.floor(_loc4_ / 2) - 1) + 1;
}
if(_loc3_ == _loc7_ - 1)
{
_loc2_ = _loc4_;
if(_loc2_ < 1)
{
_loc2_ = 1;
}
}
_loc8_.push(_loc2_);
_loc4_ -= _loc2_;
_loc3_ = _loc3_ + 1;
}
_loc11_.push(0);
_loc13_.push(_loc8_);
_loc5_ = _loc5_ + 1;
}
_loc5_ = 0;
while(_loc5_ < this.TERRITORIES_ARR.length)
{
this.TERRITORIES_ARR[_loc5_].unitsNO = _loc13_[this.TERRITORIES_ARR[_loc5_].player - 1][_loc11_[this.TERRITORIES_ARR[_loc5_].player - 1]];
_loc11_[this.TERRITORIES_ARR[_loc5_].player - 1]++;
_loc5_ = _loc5_ + 1;
}
}
function territoryA(terr)
{
this.CHOSEN_TERR_A = terr;
this.CHOSEN_TERR_B = undefined;
this.colorMC(this.CHOSEN_TERR_A.border,this.BORDER_ACTIVE_COLOR);
this.territoryMaxDepth(this.CHOSEN_TERR_A);
}
function territoryB(terr)
{
this.CHOSEN_TERR_B = terr;
this.colorMC(this.CHOSEN_TERR_B.border,this.BORDER_ACTIVE_COLOR);
var _loc2_ = 0;
while(_loc2_ < this.TERRITORIES_ARR.length)
{
if(this.TERRITORIES_ARR[_loc2_].border.getDepth() == this.CHOSEN_TERR_A.border.getDepth() - 1)
{
this.CHOSEN_TERR_B.border.swapDepths(this.TERRITORIES_ARR[_loc2_].border);
_loc2_ = this.TERRITORIES_ARR.length;
}
_loc2_ = _loc2_ + 1;
}
}
function territoryMaxDepth(terrObj)
{
var _loc6_ = this.TERRITORIES_ARR[0].border.getDepth();
var _loc2_ = new Array();
var _loc5_ = 0;
while(_loc5_ < this.TERRITORIES_ARR.length)
{
if(this.TERRITORIES_ARR[_loc5_].border.getDepth() < _loc6_)
{
_loc6_ = this.TERRITORIES_ARR[_loc5_].border.getDepth();
}
_loc2_.push(this.TERRITORIES_ARR[_loc5_].border);
this.TERRITORIES_ARR[_loc5_].border.swapDepths(_loc6_ + 10 + this.TERRITORIES_ARR.length + _loc5_);
_loc5_ = _loc5_ + 1;
}
_loc5_ = 0;
while(_loc5_ < _loc2_.length)
{
var _loc3_ = _loc2_.length - 1;
while(_loc3_ > _loc5_)
{
if(_loc2_[_loc3_ - 1].getDepth() > _loc2_[_loc3_].getDepth())
{
var _loc4_ = _loc2_[_loc3_];
_loc2_[_loc3_] = _loc2_[_loc3_ - 1];
_loc2_[_loc3_ - 1] = _loc4_;
}
_loc3_ = _loc3_ - 1;
}
_loc5_ = _loc5_ + 1;
}
_loc5_ = 0;
while(_loc5_ < _loc2_.length)
{
if(_loc2_[_loc5_] == terrObj.border)
{
_loc2_.splice(_loc5_,1);
}
_loc5_ = _loc5_ + 1;
}
_loc2_.push(terrObj.border);
_loc5_ = 0;
while(_loc5_ < _loc2_.length)
{
_loc2_[_loc5_].swapDepths(_loc6_ + _loc5_);
_loc5_ = _loc5_ + 1;
}
}
function resetTerritory(terr)
{
if(this.CHOSEN_TERR_B == terr)
{
this.CHOSEN_TERR_B = undefined;
}
if(this.CHOSEN_TERR_A == terr)
{
this.CHOSEN_TERR_A = undefined;
}
this.markTerritory(terr,terr.player,0);
}
function unMarkIfMarked()
{
this.colorMC(this.CHOSEN_TERR_A.border,this.BORDER_COLOR);
this.deselectAll();
}
function selectA()
{
if(!this.GAME_CLASS.isGameFinished())
{
var root = this;
var _loc4_ = 0;
while(_loc4_ < this.TERRITORIES_ARR.length)
{
var _loc6_ = false;
var _loc7_ = this.neighboursAreasArr(this.TERRITORIES_ARR[_loc4_].arr);
var _loc5_ = 0;
while(_loc5_ < _loc7_.length && !_loc6_)
{
if(_loc7_[_loc5_].player != this.TERRITORIES_ARR[_loc4_].player)
{
_loc6_ = true;
}
_loc5_ = _loc5_ + 1;
}
if(_loc6_)
{
_loc5_ = 0;
while(_loc5_ < this.TERRITORIES_ARR[_loc4_].arr.length)
{
var _loc3_ = this.TERRITORIES_ARR[_loc4_].arr[_loc5_];
if(_loc3_._territory.player == 1 && _loc3_._territory.unitsNO > 1)
{
_loc3_.onRelease = function()
{
_global.SOUNDS.playSound("Click- głośniejszy.wav");
if(this._territory == root.CHOSEN_TERR_A)
{
root.colorMC(root.CHOSEN_TERR_A.border,root.BORDER_COLOR);
root.lightOffTerritory(root.CHOSEN_TERR_A);
root.deselectB();
root.CHOSEN_TERR_A = undefined;
}
else
{
root.colorMC(root.CHOSEN_TERR_A.border,root.BORDER_COLOR);
root.lightOffTerritory(root.CHOSEN_TERR_A);
root.deselectB();
root.territoryA(this._territory);
root.lightOffTerritory(this._territory);
root.selectB();
}
};
_loc3_.onRollOver = function()
{
if(this._territory != root.CHOSEN_TERR_A)
{
root.lightOnTerritory(this._territory);
}
};
_loc3_.onRollOut = _loc3_.onReleaseOutside = function()
{
if(this._territory != root.CHOSEN_TERR_A)
{
root.lightOffTerritory(this._territory);
}
};
}
_loc5_ = _loc5_ + 1;
}
}
_loc4_ = _loc4_ + 1;
}
}
}
function selectB()
{
this.findAneighbours();
var root = this;
var _loc4_ = 0;
while(_loc4_ < this.TERR_A_NArr.length)
{
if(this.TERR_A_NArr[_loc4_].player != 1)
{
var _loc3_ = 0;
while(_loc3_ < this.TERR_A_NArr[_loc4_].arr.length)
{
var _loc5_ = this.TERR_A_NArr[_loc4_].arr[_loc3_];
_loc5_.onRelease = function()
{
_global.SOUNDS.playSound("Click- głośniejszy.wav");
root.territoryB(this._territory);
root.fightAB();
root.deselectAll();
};
_loc3_ = _loc3_ + 1;
}
}
_loc4_ = _loc4_ + 1;
}
}
function deselectB()
{
this.findAneighbours();
var _loc5_ = this;
var _loc3_ = 0;
while(_loc3_ < this.TERR_A_NArr.length)
{
if(this.TERR_A_NArr[_loc3_].player != 1)
{
var _loc2_ = 0;
while(_loc2_ < this.TERR_A_NArr[_loc3_].arr.length)
{
var _loc4_ = this.TERR_A_NArr[_loc3_].arr[_loc2_];
delete _loc4_.onRelease;
_loc2_ = _loc2_ + 1;
}
}
_loc3_ = _loc3_ + 1;
}
}
function deselectA()
{
var _loc5_ = this;
var _loc4_ = 0;
while(_loc4_ < this.TERR_A_NArr.length)
{
if(this.TERR_A_NArr[_loc4_].player == 1)
{
var _loc3_ = 0;
while(_loc3_ < this.TERR_A_NArr[_loc4_].arr.length)
{
var _loc2_ = this.TERR_A_NArr[_loc4_].arr[_loc3_];
delete _loc2_.onRollOut;
delete _loc2_.onReleaseOutside;
delete _loc2_.onRollOver;
delete _loc2_.onRelease;
_loc3_ = _loc3_ + 1;
}
}
_loc4_ = _loc4_ + 1;
}
}
function deselectAll()
{
var _loc3_ = 0;
while(_loc3_ < this.TERRITORIES_ARR.length)
{
var _loc2_ = 0;
while(_loc2_ < this.TERRITORIES_ARR[_loc3_].arr.length)
{
delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onRollOver;
delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onRollOut;
delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onReleaseOutside;
delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onRelease;
_loc2_ = _loc2_ + 1;
}
_loc3_ = _loc3_ + 1;
}
}
function findAneighbours()
{
this.TERR_A_NArr = new Array();
var _loc8_ = this.CHOSEN_TERR_A.arr;
var _loc7_ = 0;
while(_loc7_ < _loc8_.length)
{
var _loc6_ = _loc8_[_loc7_];
var _loc4_ = [_loc6_.TL,_loc6_.L,_loc6_.TR,_loc6_.BR,_loc6_.R,_loc6_.BL];
var _loc2_ = 0;
while(_loc2_ < _loc4_.length)
{
if(_loc4_[_loc2_]._territory != _loc6_._territory && _loc4_[_loc2_]._territory != undefined)
{
var _loc5_ = false;
var _loc3_ = 0;
while(_loc3_ < this.TERR_A_NArr.length && !_loc5_)
{
if(this.TERR_A_NArr[_loc3_] == _loc4_[_loc2_]._territory)
{
_loc5_ = true;
}
_loc3_ = _loc3_ + 1;
}
if(!_loc5_)
{
this.TERR_A_NArr.push(_loc4_[_loc2_]._territory);
}
}
_loc2_ = _loc2_ + 1;
}
_loc7_ = _loc7_ + 1;
}
}
function neighboursAreasArr(terrArr)
{
var _loc6_ = new Array();
var _loc7_ = 0;
while(_loc7_ < terrArr.length)
{
var _loc5_ = terrArr[_loc7_];
var _loc3_ = [_loc5_.TL,_loc5_.L,_loc5_.TR,_loc5_.BR,_loc5_.R,_loc5_.BL];
var _loc1_ = 0;
while(_loc1_ < _loc3_.length)
{
if(_loc3_[_loc1_]._territory != _loc5_._territory && _loc3_[_loc1_]._territory != undefined)
{
var _loc4_ = false;
var _loc2_ = 0;
while(_loc2_ < _loc6_.length && !_loc4_)
{
if(_loc6_[_loc2_] == _loc3_[_loc1_]._territory)
{
_loc4_ = true;
}
_loc2_ = _loc2_ + 1;
}
if(!_loc4_)
{
_loc6_.push(_loc3_[_loc1_]._territory);
}
}
_loc1_ = _loc1_ + 1;
}
_loc7_ = _loc7_ + 1;
}
return _loc6_;
}
function lightOnTerritory(terrObj)
{
var _loc1_ = 0;
while(_loc1_ < terrObj.arr.length)
{
terrObj.arr[_loc1_]._alpha = 70;
_loc1_ = _loc1_ + 1;
}
}
function lightOffTerritory(terrObj)
{
var _loc1_ = 0;
while(_loc1_ < terrObj.arr.length)
{
terrObj.arr[_loc1_]._alpha = 100;
_loc1_ = _loc1_ + 1;
}
}
function fightAB()
{
this.GAME_CLASS.FIGHTBOX.resetWinner();
this.GAME_CLASS.FIGHTBOX.fight(this.CHOSEN_TERR_A,this.CHOSEN_TERR_B);
}
function winnerFound()
{
if(this.GAME_CLASS.FIGHTBOX.WINNER == this.CHOSEN_TERR_A)
{
this.winA();
if(this.GAME_CLASS.PLAYER_MOVE == 1 && !this.GAME_CLASS.isGameFinished())
{
_global.setTimeout(mx.utils.Delegate.create(this.GAME_CLASS,this.GAME_CLASS.showBiggestArea),300);
}
}
if(this.GAME_CLASS.FIGHTBOX.WINNER == this.CHOSEN_TERR_B)
{
this.winB();
}
var _loc4_ = new Array();
var _loc3_ = 1;
while(_loc3_ <= this.GAME_CLASS.PLAYERS_NO)
{
_loc4_.push(this.GAME_CLASS.unitsToAdd(_loc3_));
_loc3_ = _loc3_ + 1;
}
this.GAME_CLASS.UNITS_LIST.refreshList(_loc4_,this.TERRITORIES_ARR);
}
function winA()
{
this.markTerritory(this.CHOSEN_TERR_B,this.CHOSEN_TERR_A.player,0);
this.CHOSEN_TERR_B.unitsNO = this.CHOSEN_TERR_A.unitsNO - 1;
this.CHOSEN_TERR_A.unitsNO = 1;
this.CHOSEN_TERR_B.army = this.CHOSEN_TERR_A.army;
this.CHOSEN_TERR_A.unitsMC.setUnit(this.CHOSEN_TERR_A.army,this.CHOSEN_TERR_A.unitsNO,this.CHOSEN_TERR_A.player);
this.CHOSEN_TERR_B.unitsMC.setUnit(this.CHOSEN_TERR_A.army,this.CHOSEN_TERR_B.unitsNO,this.CHOSEN_TERR_B.player);
this.resetTerritory(this.CHOSEN_TERR_A);
this.resetTerritory(this.CHOSEN_TERR_B);
this.deselectAll();
}
function winB()
{
this.CHOSEN_TERR_A.unitsNO = 1;
this.CHOSEN_TERR_A.unitsMC.setUnit(this.CHOSEN_TERR_A.army,this.CHOSEN_TERR_A.unitsNO,this.CHOSEN_TERR_A.player);
this.resetTerritory(this.CHOSEN_TERR_A);
this.resetTerritory(this.CHOSEN_TERR_B);
this.deselectAll();
}
function colorMC(mc, cl)
{
var _loc1_ = new Color(mc);
_loc1_.setRGB(cl);
}
function rad2deg(rad)
{
return rad * 180 / 3.141592653589793;
}
function deg2rad(deg)
{
return deg * 3.141592653589793 / 180;
}
function random2(z)
{
return Math.round(Math.random() * z);
}
function shuffledArray(arr)
{
var _loc5_ = 0;
while(_loc5_ < 30)
{
var _loc4_ = this.random2(arr.length - 1);
var _loc3_ = this.random2(arr.length - 1);
var _loc6_ = arr[_loc4_];
arr[_loc4_] = arr[_loc3_];
arr[_loc3_] = _loc6_;
_loc5_ = _loc5_ + 1;
}
return arr;
}
function clearAll()
{
var _loc2_ = 0;
while(_loc2_ < this.rubbish_arr.length)
{
this.rubbish_arr[_loc2_].removeMovieClip();
_loc2_ = _loc2_ + 1;
}
}
}